<?php

namespace App\Api\Controller;


use App\Api\Transformers\ClubAllTransformer;
use App\Api\Transformers\ClubInfoTransformer;
use App\Api\Transformers\ClubLessonTransformer;
use App\Club;
use App\ClubCoaches;
use App\ClubLessons;
use Illuminate\Http\Request;


/**
 * Class ClubController
 * @package App\Api\Controller
 */
class ClubController extends BaseController
{
    /**
     * return all club
     *
     * @return \Dingo\Api\Http\Response
     */
    public function index()
    {
        $club = Club::all();

        return $this->response->collection($club, new ClubAllTransformer());
    }

    /**
     * return club all info
     *
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     */
     public function show(Request $request)
     {
         $club_id = $request->get('club_id');
         $clubInfo = Club::where('id',$club_id)->get();
         if ($clubInfo->isEmpty())
         {
             return $this->response->errorNotFound('未找到该俱乐部详情');
         }
         return $this->response->collection($clubInfo, new ClubInfoTransformer());
     }

     /**
     * return Club Lesson
     *
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     */
    public function clubLesson(Request $request)
    {
        $club_id = $request->get('club_id');
        $clubLesson = ClubLessons::where('club_id',$club_id)->select('id', 'club_id', 'lesson_name', 'lesson_intro', 'lesson_price', 'lesson_star')->get();
        if($clubLesson->isEmpty())
        {
            return $this->response->errorNotFound('未找到该俱乐部课程详情');
        }
        return $this->response->item($clubLesson, new ClubLessonTransformer());
    }
}